<template>
  <el-container>
    <el-aside width="400px">
      <el-row type="flex" justify="space-between">
        <el-col :span="12"><el-tag>患者选择</el-tag></el-col>
        <el-col :span="12"><el-button type="primary" icon="el-icon-refresh" size="small" style="float:right" @click="patientRefresh"></el-button></el-col>
      </el-row>
      <el-row>
        <el-form :inline="true" :model="formInline">
          <el-form-item label="患者名：">
            <el-input v-model="formInline.content" placeholder="请输入姓名或者病历号"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch">查询</el-button>
          </el-form-item>
        </el-form>
      </el-row>
      <el-row>
        <el-table :data="searchMember" @row-click="selectPatient">
          <el-table-column prop="patientId" label="编号"></el-table-column>
          <el-table-column prop="name" label="姓名"></el-table-column>
          <el-table-column prop="age" label="年龄"></el-table-column>
        </el-table>
      </el-row>
      <el-row>
        <el-tabs type="card">
          <el-tab-pane label="本人">
            <el-row>
              <el-tag>已诊患者：</el-tag>
            </el-row>
            <el-row>
              <el-table :data="memberUseryizhen" @row-click="selectPatient">
                <el-table-column prop="patientId" label="编号"></el-table-column>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="age" label="年龄"></el-table-column>
              </el-table>
            </el-row>
            <el-row>
              <el-tag>未诊患者：</el-tag>
            </el-row>
            <el-row>
              <el-table :data="memberUserweizhen" @row-click="selectPatient">
                <el-table-column prop="patientId" label="编号"></el-table-column>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="age" label="年龄"></el-table-column>
              </el-table>
            </el-row>            
          </el-tab-pane>
          <el-tab-pane label="科室">
            <el-row>
              <el-tag>已诊患者：</el-tag>
            </el-row>
            <el-row>
              <el-table :data="memberDeptyizhen" @row-click="selectPatient">
                <el-table-column prop="patientId" label="编号"></el-table-column>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="age" label="年龄"></el-table-column>
              </el-table>
            </el-row>
            <el-row>
              <el-tag>未诊患者：</el-tag>
            </el-row>
            <el-row>
              <el-table :data="memberDeptweizhen" @row-click="selectPatient">
                <el-table-column prop="patientId" label="编号"></el-table-column>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="age" label="年龄"></el-table-column>
              </el-table>
            </el-row>             
          </el-tab-pane>
        </el-tabs>
      </el-row>
    </el-aside>
    <el-main>
      <el-row class="main-row">
        <el-col :span="2">
          <el-tag>患者信息：</el-tag>
        </el-col>
        <el-col :span="20" style="height:32px">
          <p v-if="patient.name != '' ">{{
            "患者姓名: " + this.patient.name + " 病历号: " + this.patient.patientId + " 年龄: " + this.patient.age + " 性别: " + this.patient.gender
            }}</p>
            <p v-else>未选中患者</p>
        </el-col>
        <el-col :span="2">
          <el-button size="small" type="primary" style="float:right" @click="zhenbi">诊毕</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-tabs type="card">
          <el-tab-pane label="病历首页">
            <el-row class="main-row back">
              <el-col :span="5" :offset="4"><el-button type="primary" size="small" @click="saveBingli">暂存</el-button></el-col>
              <el-col :span="5" ><el-button type="primary" size="small" @click="submitBingli">提交</el-button></el-col>
              <el-col :span="5" ><el-button type="primary" size="small" @click="clearBingli">清空</el-button></el-col>
              <el-col :span="5" ><el-button type="primary" size="small" @click="refreshBingli">刷新</el-button></el-col>
            </el-row>
            <el-row>
              <el-tag>病史内容：</el-tag>
            </el-row>
            <el-row class="main-row">
              <el-form ref="bingLiForm" :model="bingLiForm" label-width="100px" width="1200px">
                <el-form-item label="主诉">
                  <el-input v-model="bingLiForm.zhusu"></el-input>
                </el-form-item>
                <el-form-item label="现病史">
                  <el-input v-model="bingLiForm.xianbing"></el-input>
                </el-form-item>
                <el-form-item label="现病治疗情况">
                  <el-input v-model="bingLiForm.zhiliao"></el-input>
                </el-form-item>
                <el-form-item label="既往史">
                  <el-input v-model="bingLiForm.jiwang"></el-input>
                </el-form-item>
                <el-form-item label="过敏史">
                  <el-input v-model="bingLiForm.guomin"></el-input>
                </el-form-item>
                <el-form-item label="体格检查">
                  <el-input v-model="bingLiForm.tige"></el-input>
                </el-form-item>
              </el-form>
            </el-row>
            <el-row>
              <el-tag>评估/诊断：</el-tag>
            </el-row>
            <el-row class="main-row">
              <el-card>
                <div slot="header" class="clearfix">
                  <span style="float:left">西医诊断</span>
                  <el-button style="float:right" @click="deleteXiData">删除</el-button>
                  <el-button style="float:right" @click="updateXiData">增加</el-button>
                </div>
                <div>
                  <el-table 
                  ref="xiData" 
                  class="tb-edit"
                  highlight-current-row
                  :data="xiData" 
                  :row-class-name="tableRowClassName"
                  @selection-change="handleXiSelectionChange">
                    <el-table-column type="selection" width="100px"></el-table-column>
                    <el-table-column prop="icd" label="ICD编码" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.icd" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.icd}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="name" label="名称" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.name" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.name}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="time" label="发病时间">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.time" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.time}}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-card>
            </el-row>
            <el-row class="main-row">
              <el-card>
                <div slot="header" class="clearfix">
                  <span style="float:left">中医诊断</span>
                  <el-button style="float:right" @click="deleteZhongData">删除</el-button>
                  <el-button style="float:right" @click="updateZhongData">增加</el-button>
                </div>
                <div>
                  <el-table 
                  ref="zhongData" 
                  class="tb-edit"
                  highlight-current-row
                  :data="zhongData" 
                  :row-class-name="tableRowClassName"
                  @selection-change="handleZhongSelectionChange">
                    <el-table-column type="selection" width="100px"></el-table-column>
                    <el-table-column prop="icd" label="ICD编码" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.icd" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.icd}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="name" label="名称" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.name" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.name}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="time" label="发病时间">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.time" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.time}}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-card>              
            </el-row>
            <el-row class="main-row">
              <el-form :model="bingLiForm" label-width="100px" width="1200px">
                <el-form-item label="检查建议">
                  <el-input v-model="bingLiForm.jianyi"></el-input>
                </el-form-item>
                <el-form-item label="注意事项">
                  <el-input v-model="bingLiForm.zhuyi"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="submitBingli">提交</el-button>
                </el-form-item>
              </el-form>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="检查申请">
            <el-row class="main-row">
              <el-col :span="16">
                <el-row class="back">
                  <el-col :span="4" >
                    <el-popover
                      trigger="click">
                      <el-card>
                        <div class="clearfix">
                          <span>新增项目</span>
                          <el-button size="small" style="float:right" @click="addJiancha">增加</el-button>
                        </div>
                        <div>
                          <el-table 
                          ref="jianchaAdd"
                          :data="jianchaAdd"
                          @selection-change="handleJianchaAddSelection">
                            <el-table-column type="selection"></el-table-column>
                            <el-table-column width="100px" property="projName" label="名称"></el-table-column>
                            <el-table-column width="100px" property="price" label="价格"></el-table-column>
                            <el-table-column width="100px" property="deptId" label="科室"></el-table-column>
                          </el-table>
                        </div>
                      </el-card>
                      <el-button slot="reference" type="primary" size="small">新建项目</el-button>
                    </el-popover>
                  </el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="deleteJiancha">删除项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="saveJianchaPro">暂存项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="submitJianchaPro">开立项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="deleteJianchaPro">作废项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="refreshJianchaPro">刷新</el-button></el-col>
                </el-row>
                <el-row>
                  <el-tag>本项目金额合计</el-tag>
                  <el-tag type="warning">{{this.jianchaCost}}元</el-tag>
                </el-row>
                <el-row>
                  <el-table 
                  ref="jianchaPro"
                  :data="jianchaPro"
                  :row-class-name="tableRowClassName"
                  class="tb-edit"
                  highlight-current-row
                  @selection-change="handleJianchaSelectionChange">
                    <el-table-column type="selection" width="50px"></el-table-column>
                    <el-table-column label="申请名称" width="120px" prop="applyName">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.applyName"></el-input>
                        <span>{{scope.row.applyName}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="项目名称" width="120px" prop="proName">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.proName"></el-input>
                        <span>{{scope.row.proName}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="执行科室" width="120px" prop="dept">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.dept"></el-input>
                        <span>{{scope.row.dept}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="执行状态" width="120px" prop="state">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.state"></el-input>
                        <span>{{scope.row.state}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="单价" width="100px" prop="price">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.price"></el-input>
                        <span>{{scope.row.price}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="检查结果" width="100px" prop="result"> 
                      <template slot-scope="scope">
                        <el-popover
                        placement="bottom"
                        trigger="click">
                          <el-card><p>{{scope.row.result}}</p></el-card>
                          <el-button slot="reference" type="text" @click="getProResult(scope.row)">检查结果</el-button>
                        </el-popover>                    
                      </template>
                    </el-table-column>
                  </el-table>
                </el-row>
              </el-col>
              <el-col :span="8">
                <el-tabs type="card">
                  <el-tab-pane label="常用模板">
                    <el-table
                    :data="temJianchaTable">
                      <el-table-column label="名称" prop="name">
                      </el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <el-button type="text" @click="useJianchaTem(scope.row)">使用</el-button>
                          <el-popover
                          placement="bottom"
                          trigger="click">
                            <el-card><p>{{scope.row.detail}}</p></el-card>
                            <el-button slot="reference" type="text">详细</el-button>
                        </el-popover>  
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                </el-tabs>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="检验申请">
            <el-row class="main-row">
              <el-col :span="16">
                <el-row class="back">
                  <el-col :span="4" >
                    <el-popover
                      trigger="click">
                      <el-card>
                        <div class="clearfix">
                          <span>新增项目</span>
                          <el-button size="small" style="float:right" @click="addJianyan">增加</el-button>
                        </div>
                        <div>
                          <el-table 
                          :data="jianyanAdd"
                          ref="jianyanAdd"
                          @selection-change="handleJianyanAddSelection">
                            <el-table-column type="selection"></el-table-column>
                            <el-table-column width="100px" property="projName" label="名称"></el-table-column>
                            <el-table-column width="100px" property="price" label="价格"></el-table-column>
                            <el-table-column width="100px" property="deptId" label="科室"></el-table-column>
                          </el-table>
                        </div>
                      </el-card>
                      <el-button slot="reference" type="primary" size="small">新建项目</el-button>
                    </el-popover>
                  </el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="deleteJianyan">删除项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="saveJianyanPro">暂存项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="submitJianyanPro">开立项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="deleteJianyanPro">作废项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="refreshJianyanPro">刷新</el-button></el-col>
                </el-row>
                <el-row>
                  <el-tag>本项目金额合计</el-tag>
                  <el-tag type="warning">{{this.jianyanCost}}元</el-tag>
                </el-row>
                <el-row>
                  <el-table 
                  ref="jianyanPro"
                  :data="jianyanPro"
                  :row-class-name="tableRowClassName"
                  class="tb-edit"
                  highlight-current-row
                  @selection-change="handleJianyanSelectionChange">
                    <el-table-column type="selection" width="50px"></el-table-column>
                    <el-table-column label="申请名称" width="120px" prop="applyName">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.applyName"></el-input>
                        <span>{{scope.row.applyName}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="项目名称" width="120px" prop="proName">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.proName"></el-input>
                        <span>{{scope.row.proName}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="执行科室" width="120px" prop="dept">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.dept"></el-input>
                        <span>{{scope.row.dept}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="执行状态" width="120px" prop="state">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.state"></el-input>
                        <span>{{scope.row.state}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="单价" width="100px" prop="price">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.price"></el-input>
                        <span>{{scope.row.price}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="检查结果" width="100px"> 
                      <template slot-scope="scope">                    
                        <el-popover
                        placement="bottom"
                        trigger="click">
                          <el-card><p>{{scope.row.result}}</p></el-card>
                          <el-button slot="reference" type="text" @click="getProResult(scope.row)">检查结果</el-button>
                        </el-popover>  
                      </template>
                    </el-table-column>
                  </el-table>
                </el-row>
              </el-col>
              <el-col :span="8">
                <el-tabs type="card">
                  <el-tab-pane label="常用模板">
                    <el-table
                    :data="temJianyanTable">
                      <el-table-column label="名称" prop="name">
                      </el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <el-button type="text" @click="useJianyanTem(scope.row)">使用</el-button>
                          <el-button type="text">详细</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                </el-tabs>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="门诊确诊">
            <el-row class="main-row">
              <el-tag>最终诊断结果：</el-tag>
              <el-button @click="importQuezhen" type="primary" size="small" style="float:right">导入</el-button>
            </el-row>
            <el-row class="main-row">
              <el-card>
                <div slot="header" class="clearfix">
                  <span style="float:left">西医诊断</span>
                  <el-button style="float:right" @click="deleteXiQuezhenData">删除</el-button>
                  <el-button style="float:right" @click="updateXiQuezhenData">增加</el-button>
                </div>
                <div>
                  <el-table 
                  ref="xiQuezhenData" 
                  :data="xiQuezhenData"
                  class="tb-edit"
                  highlight-current-row
                  :row-class-name="tableRowClassName"
                  @selection-change="handleXiQuezhenSelectionChange">
                    <el-table-column type="selection" width="100px"></el-table-column>
                    <el-table-column prop="icd" label="ICD编码" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.icd" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.icd}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="name" label="名称" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.name" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.name}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="time" label="发病时间">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.time" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.time}}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-card> 
            </el-row>
            <el-row class="main-row">
              <el-card>
                <div slot="header" class="clearfix">
                  <span style="float:left">中医诊断</span>
                  <el-button style="float:right" @click="deleteZhongQuezhenData">删除</el-button>
                  <el-button style="float:right" @click="updateZhongQuezhenData">增加</el-button>
                </div>
                <div>
                  <el-table 
                  ref="zhongQuezhenData" 
                  :data="zhongQuezhenData"
                  class="tb-edit"
                  highlight-current-row
                  :row-class-name="tableRowClassName"
                  @selection-change="handleZhongQuezhenSelectionChange">
                    <el-table-column type="selection" width="100px"></el-table-column>
                    <el-table-column prop="icd" label="ICD编码" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.icd" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.icd}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="name" label="名称" width="300px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.name" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.name}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="time" label="发病时间">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.time" placeholder="请输入内容"></el-input>
                        <span>{{scope.row.time}}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-card>               
            </el-row>
            <el-row class="main-row">
              <el-form :model="quezhenForm">
                <el-form-item label="检查结果">
                  <el-input type="textarea" v-model="quezhenForm.jianchaResult"></el-input>
                </el-form-item>
                <el-form-item label="检验结果">
                  <el-input type="textarea" v-model="quezhenForm.jianyanResult"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="submitQuehzhen">提交</el-button>
                </el-form-item> 
              </el-form>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="处置申请">
            <el-row class="main-row">
              <el-col :span="16">
                <el-row class="back">
                  <el-col :span="4" >
                    <el-popover
                      trigger="click">
                      <el-card>
                        <div class="clearfix">
                          <span>新增项目</span>
                          <el-button size="small" style="float:right" @click="addChuzhi">增加</el-button>
                        </div>
                        <div>
                          <el-table 
                          :data="chuzhiAdd"
                          ref="chuzhiAdd"
                          @selection-change="handleChuzhiAddSelection">
                            <el-table-column type="selection"></el-table-column>
                            <el-table-column width="100px" property="projName" label="名称"></el-table-column>
                            <el-table-column width="100px" property="price" label="价格"></el-table-column>
                            <el-table-column width="100px" property="deptId" label="科室"></el-table-column>
                          </el-table>
                        </div>
                      </el-card>
                      <el-button slot="reference" type="primary" size="small">新建项目</el-button>
                    </el-popover>
                  </el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="deleteChuzhi">删除项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="saveChuzhiPro">暂存项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="submitChuzhiPro">开立项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="deleteChuzhiPro">作废项目</el-button></el-col>
                  <el-col :span="4" ><el-button type="primary" size="small" @click="refreshChuzhiPro">刷新</el-button></el-col>
                </el-row>
                <el-row>
                  <el-tag>本项目金额合计</el-tag>
                  <el-tag type="warning">{{this.chuzhiCost}}元</el-tag>
                </el-row>
                <el-row>
                  <el-table 
                  ref="chuzhiPro"
                  :data="chuzhiPro"
                  :row-class-name="tableRowClassName"
                  class="tb-edit"
                  highlight-current-row
                  @selection-change="handleChuzhiSelectionChange">
                    <el-table-column type="selection" width="50px"></el-table-column>
                    <el-table-column label="申请名称" width="120px" prop="applyName">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.applyName"></el-input>
                        <span>{{scope.row.applyName}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="项目名称" width="120px" prop="proName">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.proName"></el-input>
                        <span>{{scope.row.proName}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="执行科室" width="120px" prop="dept">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.dept"></el-input>
                        <span>{{scope.row.dept}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="执行状态" width="120px" prop="state">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.state"></el-input>
                        <span>{{scope.row.state}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="单价" width="100px" prop="price">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.price"></el-input>
                        <span>{{scope.row.price}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="检查结果" width="100px"> 
                      <template slot-scope="scope">                    
                        <el-popover
                        placement="bottom"
                        trigger="click">
                          <el-card><p>{{scope.row.result}}</p></el-card>
                          <el-button slot="reference" type="text" @click="getProResult(scope.row)">检查结果</el-button>
                        </el-popover>  
                      </template>
                    </el-table-column>
                  </el-table>
                </el-row>
              </el-col>
              <el-col :span="8">
                <el-tabs type="card">
                  <el-tab-pane label="常用模板">
                    <el-table
                    :data="temChuzhiTable">
                      <el-table-column label="名称" prop="name">
                      </el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <el-button type="text" @click="useChuzhiTem(scope.row)">使用</el-button>
                          <el-button type="text">详细</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                  </el-tab-pane>
                </el-tabs>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="成药处方">
            <el-row>
              <el-tag>门诊诊断：</el-tag>
              <el-tag type="info" v-for="item in xiQuezhenData" :key="item.name">【西医诊断】{{item.name}}</el-tag>
            </el-row>
            <el-row class="main-row back">
              <el-col :span="2" :offset="6">
                <el-button size="small" type="primary" @click="updateXiChufangData">增方</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="primary" @click="deleteXiChufangData">删方</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="primary" @click="submitXiChufang">开立</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="primary" @click="deleteXiChufang">作废</el-button>
              </el-col>
              <el-col :span="2" :offset="3">
                <el-popover
                  trigger="click"
                  placement="bottom">
                  <el-card>
                    <div class="clearfix">
                      <span>新增药品</span>
                      <el-button size="small" style="float:right" @click="addXiDrug">增加</el-button>
                    </div>
                    <div>
                      <el-table
                      ref="drugXiTableData"
                      :data="drugXiTableData"
                      highlight-current-row
                      @selection-change="handleDrugXiSelectionChange">
                        <el-table-column type="selection" width="50px"></el-table-column>
                        <el-table-column prop="name" label="药品名称" width="300px"></el-table-column>
                        <el-table-column prop="standard" label="规格" width="100px"></el-table-column>
                        <el-table-column prop="price" label="单价" width="80px"></el-table-column>
                        <el-table-column prop="use" label="用法" width="100px"></el-table-column>
                        <el-table-column prop="dose" label="用量" width="60px"></el-table-column>
                        <el-table-column prop="fre" label="频次" width="60px"></el-table-column>
                      </el-table>
                    </div>
                  </el-card>
                  <el-button slot="reference" type="info" size="small">增药</el-button>
                </el-popover>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="info" @click="deleteXiDrug">删药</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="info" @click="saveXiChufang">保存处方</el-button>
              </el-col>
            </el-row>
            <el-row class="main-row">
              <el-col :span="6">
                <el-row>
                  <el-tag type="info">门诊处方</el-tag>
                </el-row>
                <el-row>
                  <el-table
                  ref="chufangXiData" 
                  class="tb-edit"
                  highlight-current-row
                  :data="chufangXiData" 
                  :row-class-name="tableRowClassName"
                  @selection-change="handleXiChufangSelectionChange"
                  @row-click="handleXiClickChuFang">
                    <el-table-column type="selection" width="60px"></el-table-column>
                    <el-table-column label="名称"  prop="name">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.name"></el-input>
                        <span>{{scope.row.name}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="状态" prop="state">
                    </el-table-column>
                  </el-table>
                </el-row>
              </el-col>
              <el-col :span="18">
                <el-row>
                  <el-tag>本处方金额合计：</el-tag>
                  <el-tag type="warning">{{refreshXiCost()}}元</el-tag>
                </el-row>
                <el-row>
                  <el-table
                  :data="drugXiList"
                  ref="drugXiList" 
                  class="tb-edit"
                  highlight-current-row
                  :row-class-name="tableRowClassName"
                  @selection-change="handleDrugXiListSelectionChange">
                    <el-table-column type="selection" width="50px"></el-table-column>
                    <el-table-column prop="name" label="药品名称" width="300px"></el-table-column>
                    <el-table-column prop="standard" label="规格" width="100px"></el-table-column>
                    <el-table-column prop="price" label="单价" width="80px"></el-table-column>
                    <el-table-column prop="use" label="用法" width="100px"></el-table-column>
                    <el-table-column prop="dose" label="用量" width="60px"></el-table-column>
                    <el-table-column prop="fre" label="频次" width="60px"></el-table-column>
                    <el-table-column prop="num" label="数量" width="60px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.num"></el-input>
                        <span>{{scope.row.num}}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </el-row>
              </el-col>
            </el-row>
            <el-row class="main-row">
              <el-tabs type="card">
                <el-tab-pane label="处方模板">
                  <el-row>
                    <el-col :span="8">
                      <el-row>
                        <el-form :inline="true" :model="formTemXiSearch">
                          <el-form-item label="名称：">
                            <el-input v-model="formTemXiSearch.content" placeholder="请输入模板名称"></el-input>
                          </el-form-item>
                          <el-form-item>
                            <el-button type="primary" @click="searchXiTem">查询</el-button>
                          </el-form-item>
                        </el-form>
                      </el-row>
                      <el-row>
                        <el-table :data="searchXiTemplate"  @row-click="selectXiTem">
                          <el-table-column prop="tem_name" label="模板名称" width="280px">
                          </el-table-column>
                          <el-table-column prop="scope" label="范围" width="80px">
                          </el-table-column>
                        </el-table>
                      </el-row>                      
                    </el-col>
                    <el-col :span="16">
                      <el-card class="box-card">
                        <div slot="header" class="clearfix">
                          <span style="float:left">模板明细</span>
                          <el-button style="float:right" @click="useXiMuban">使用该模板</el-button>
                        </div>
                        <div>
                          <el-table :data="mubanXiData">
                            <el-table-column label="药品名称" prop="name" width="250px"></el-table-column>
                            <el-table-column label="规格" prop="standard" width="200px"></el-table-column>
                            <el-table-column label="单价" prop="price" width="50px"></el-table-column>
                            <el-table-column label="用法" prop="use" width="50px"></el-table-column>
                            <el-table-column label="用量" prop="dose" width="50px"></el-table-column>
                            <el-table-column label="频次" prop="fre" width="50px"></el-table-column>
                          </el-table>
                        </div>
                      </el-card>
                    </el-col>
                  </el-row>
                </el-tab-pane>
                <el-tab-pane label="常用药品">
                  <el-table
                  :data="drugXiCommon">
                    <el-table-column prop="name" label="药品名称"></el-table-column>
                    <el-table-column prop="standard" label="规格"></el-table-column>
                    <el-table-column prop="price" label="单价"></el-table-column>
                    <el-table-column prop="use" label="用法"></el-table-column>
                    <el-table-column prop="dose" label="用量"></el-table-column>
                    <el-table-column prop="fre" label="频次"></el-table-column>
                  </el-table>
                </el-tab-pane>
              </el-tabs>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="草药处方">
            <el-row>
              <el-tag>门诊诊断：</el-tag>
              <el-tag type="info" v-for="item in zhongQuezhenData" :key="item.name">【中医诊断】{{item.name}}</el-tag>
            </el-row>
            <el-row class="main-row back">
              <el-col :span="2" :offset="6">
                <el-button size="small" type="primary" @click="updateZhongChufangData">增方</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="primary" @click="deleteZhongChufangData">删方</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="primary" @click="submitZhongChufang">开立</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="primary" @click="deleteZhongChufang">作废</el-button>
              </el-col>
              <el-col :span="2" :offset="3">
                <el-popover
                  trigger="click"
                  placement="bottom">
                  <el-card>
                    <div class="clearfix">
                      <span>新增药品</span>
                      <el-button size="small" style="float:right" @click="addZhongDrug">增加</el-button>
                    </div>
                    <div>
                      <el-table
                      ref="drugZhongTableData"
                      :data="drugZhongTableData"
                      highlight-current-row
                      @selection-change="handleDrugZhongSelectionChange">
                        <el-table-column type="selection" width="50px"></el-table-column>
                        <el-table-column prop="name" label="药品名称" width="300px"></el-table-column>
                        <el-table-column prop="standard" label="规格" width="100px"></el-table-column>
                        <el-table-column prop="price" label="单价" width="80px"></el-table-column>
                        <el-table-column prop="use" label="用法" width="100px"></el-table-column>
                        <el-table-column prop="dose" label="用量" width="60px"></el-table-column>
                        <el-table-column prop="fre" label="频次" width="60px"></el-table-column>
                      </el-table>
                    </div>
                  </el-card>
                  <el-button slot="reference" type="info" size="small">增药</el-button>
                </el-popover>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="info" @click="deleteZhongDrug">删药</el-button>
              </el-col>
              <el-col :span="2">
                <el-button size="small" type="info" @click="saveZhongChufang">保存处方</el-button>
              </el-col>
            </el-row>
            <el-row class="main-row">
              <el-col :span="6">
                <el-row>
                  <el-tag type="info">门诊处方</el-tag>
                </el-row>
                <el-row>
                  <el-table
                  ref="chufangZhongData" 
                  class="tb-edit"
                  highlight-current-row
                  :data="chufangZhongData" 
                  :row-class-name="tableRowClassName"
                  @selection-change="handleZhongChufangSelectionChange"
                  @row-click="handleZhongClickChuFang">
                    <el-table-column type="selection" width="60px"></el-table-column>
                    <el-table-column label="名称"  prop="name">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.name"></el-input>
                        <span>{{scope.row.name}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="状态" prop="state">
                    </el-table-column>
                  </el-table>
                </el-row>
              </el-col>
              <el-col :span="18">
                <el-row>
                  <el-tag>本处方金额合计：</el-tag>
                  <el-tag type="warning">{{refreshZhongCost()}}元</el-tag>
                </el-row>
                <el-row>
                  <el-table
                  :data="drugZhongList"
                  ref="drugZhongList" 
                  class="tb-edit"
                  highlight-current-row
                  :row-class-name="tableRowClassName"
                  @selection-change="handleDrugZhongListSelectionChange">
                    <el-table-column type="selection" width="50px"></el-table-column>
                    <el-table-column prop="name" label="药品名称" width="300px"></el-table-column>
                    <el-table-column prop="standard" label="规格" width="100px"></el-table-column>
                    <el-table-column prop="price" label="单价" width="80px"></el-table-column>
                    <el-table-column prop="use" label="用法" width="100px"></el-table-column>
                    <el-table-column prop="dose" label="用量" width="60px"></el-table-column>
                    <el-table-column prop="fre" label="频次" width="60px"></el-table-column>
                    <el-table-column prop="num" label="数量" width="60px">
                      <template slot-scope="scope">
                        <el-input v-model="scope.row.num"></el-input>
                        <span>{{scope.row.num}}</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </el-row>
              </el-col>
            </el-row>
            <el-row class="main-row">
              <el-tabs type="card">
                <el-tab-pane label="处方模板">
                  <el-row>
                    <el-col :span="8">
                      <el-row>
                        <el-form :inline="true" :model="formTemZhongSearch">
                          <el-form-item label="名称：">
                            <el-input v-model="formTemZhongSearch.content" placeholder="请输入模板名称"></el-input>
                          </el-form-item>
                          <el-form-item>
                            <el-button type="primary" @click="searchZhongTem">查询</el-button>
                          </el-form-item>
                        </el-form>
                      </el-row>
                      <el-row>
                        <el-table :data="searchZhongTemplate"  @row-click="selectZhongTem">
                          <el-table-column prop="tem_name" label="模板名称" width="280px">
                          </el-table-column>
                          <el-table-column prop="scope" label="范围" width="80px">
                          </el-table-column>
                        </el-table>
                      </el-row>                      
                    </el-col>
                    <el-col :span="16">
                      <el-card class="box-card">
                        <div slot="header" class="clearfix">
                          <span style="float:left">模板明细</span>
                          <el-button style="float:right" @click="useZhongMuban">使用该模板</el-button>
                        </div>
                        <div>
                          <el-table :data="mubanZhongData">
                            <el-table-column label="药品名称" prop="name" width="250px"></el-table-column>
                            <el-table-column label="规格" prop="standard" width="200px"></el-table-column>
                            <el-table-column label="单价" prop="price" width="50px"></el-table-column>
                            <el-table-column label="用法" prop="use" width="50px"></el-table-column>
                            <el-table-column label="用量" prop="dose" width="50px"></el-table-column>
                            <el-table-column label="频次" prop="fre" width="50px"></el-table-column>
                          </el-table>
                        </div>
                      </el-card>
                    </el-col>
                  </el-row>
                </el-tab-pane>
                <el-tab-pane label="常用药品">
                  <el-table
                  :data="drugZhongCommon">
                    <el-table-column prop="name" label="药品名称"></el-table-column>
                    <el-table-column prop="standard" label="规格"></el-table-column>
                    <el-table-column prop="price" label="单价"></el-table-column>
                    <el-table-column prop="use" label="用法"></el-table-column>
                    <el-table-column prop="dose" label="用量"></el-table-column>
                    <el-table-column prop="fre" label="频次"></el-table-column>
                  </el-table>
                </el-tab-pane>
              </el-tabs>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="费用查询">
            <el-row class="main-row">
              <el-form :inline="true" :model="costSearchInline">
                <el-form-item label="病历号">
                  <el-input v-model="costSearchInline.id" placeholder="请输入病历号"></el-input>
                </el-form-item>
                <el-form-item label="项目类型">
                  <el-select v-model="costSearchInline.type" placeholder="项目类型">
                    <el-option label="任何类型" value="任何"></el-option>
                    <el-option label="检查项目" value="检查"></el-option>
                    <el-option label="检验项目" value="检验"></el-option>
                    <el-option label="处置项目" value="处置"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="selectProCost">查询</el-button>
                </el-form-item>
              </el-form>
            </el-row>
            <el-row>
              <el-table :data="costTable" :default-sort="{prop: 'date', order: 'ascending'}">
                <el-table-column prop="time" sorttable label="时间"></el-table-column>
                <el-table-column prop="name" label="项目名"></el-table-column>
                <el-table-column prop="price" label="单价"></el-table-column>
                <el-table-column prop="number" label="数量"></el-table-column>
                <el-table-column prop="cost" label="金额"></el-table-column>
              </el-table>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-row>
    </el-main>
  </el-container>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
    //患者栏
      me: {
        userId: '',
        deptId: ''
      },
      formInline: {
        content: ''
      },
      searchMember: [],
      memberUseryizhen: [],
      memberUserweizhen: [],
      memberDeptyizhen: [],
      memberDeptweizhen: [],
      patient: {
        patientId: '',
        name: '',
        gender: '',
        age: ''
      },

    //病历首页
      bingLiForm: {
        zhusu: '',
        xianbing: '',
        zhiliao: '',
        jiwang: '',
        guomin: '',
        tige: '',
        jianyi: '',
        zhuyi: ''
      },
      xiData: [],
      zhongData: [],
      xiMulSelection: [],
      zhongMulSelection: [],

    //检查申请
      jianchaPro: [],
      jianchaMulSelection: [], //选中项目删除使用
      jianchaAdd: [],   //项目库
      jianchaAddSelection: [],
      jianchaNameList: [],
      jianchaStateList: [],
      temJianchaTable: [],
      jianchaCost: 0,

    //检验申请
      jianyanPro: [],
      jianyanMulSelection: [], 
      jianyanAdd: [],  
      jianyanAddSelection: [],
      jianyanResult: '',
      jianyanNameList: [],
      jianyanStateList: [],
      temJianyanTable: [],
      jianyanCost: 0,

    //门诊确诊
      quezhenForm: {
        jianchaResult: '',
        jianyanResult: ''
      },

      xiQuezhenData: [],
      zhongQuezhenData: [],
      zhongQuezhenMulSelection: [],
      xiQuezhenMulSelection: [],

    //处置申请
      chuzhiPro: [],
      chuzhiMulSelection: [], 
      chuzhiAdd: [],  
      chuzhiAddSelection: [],
      chuzhiResult: '',
      chuzhiNameList: [],
      chuzhiStateList: [],
      temChuzhiTable: [],
      chuzhiCost: 0,

    //成药处方
      chufangXiData: [],
      chufangXiMulSelection: [],
      formTemXiSearch: {
        content: ''
      },
      searchXiTemplate: [],
      mubanXiData: [],
      drugXiTableData: [],
      drugXiCommon: [],
      drugXiAdd: [],
      drugXiList: [],
      drugListXiMulSelection: [],
      selectedXiTemName: '',
      selectedXiChufangIndex: -1,
    //草药处方
      chufangZhongData: [],
      chufangZhongMulSelection: [],
      formTemZhongSearch: {
        content: ''
      },
      searchZhongTemplate: [],
      mubanZhongData: [],
      drugZhongTableData: [],
      drugZhongCommon: [],
      drugZhongAdd: [],
      drugZhongList: [],
      drugListZhongMulSelection: [],
      selectedZhongTemName: '',
      selectedZhongChufangIndex: -1,
      
    //费用查询
      costSearchInline: {
        id: '',
        type: ''
      },
      costTable: []
    }
  },
  created() {
    this.getMemberList();
    sessionStorage.removeItem("patient");
    this.getJianchaAdd();
    this.getJianyanAdd();
    this.getChuzhiAdd();
    this.getApplyTemList();
    this.getXiDrugList();
  },
  methods: {
  //---------------------------------侧边栏-----------------------------
    //设置row对象的index
    tableRowClassName(row) {
      row.row.index = row.rowIndex;
    },
    
    //患者侧边栏
    //得到患者列表
    getMemberList(){
      var user = JSON.parse(sessionStorage.getItem("user"));
      //console.log(sessionStorage.getItem('user'));
      //console.log(typeof(sessionStorage.getItem('user'))); 
      //string
      this.me.userId = user.userId;
      this.me.deptId = user.deptId;
      axios
        .get("api/menZhen/getUserMemberList", {
          params: {
            userId: this.me.userId,
            stateId: 0
          }
        })
        .then(res => {
          //console.log(res);
          this.memberUserweizhen = res.data;
        })
        .catch(error => {
          console.log(error);
        })
        axios
        .get("api/menZhen/getUserMemberList", {
          params: {
            userId: this.me.userId,
            stateId: 1
          }
        })
        .then(res => {
          //console.log(res);
          this.memberUseryizhen = res.data;
        })
        .catch(error => {
          console.log(error);
        })
        axios
        .get("api/menZhen/getDeptMemberList", {
          params: {
            deptId: this.me.deptId,
            stateId: 0
          }
        })
        .then(res => {
          //console.log(res);
          this.memberDeptweizhen = res.data;
        })
        .catch(error => {
          console.log(error);
        })
        axios
        .get("api/menZhen/getDeptMemberList", {
          params: {
            deptId: this.me.deptId,
            stateId: 1
          }
        })
        .then(res => {
          //console.log(res);
          this.memberDeptyizhen = res.data;
        })
        .catch(error => {
          console.log(error);
        })
    },

    //刷新按钮点击
    patientRefresh() {
      this.getMemberList();
    },

    //选中表格中的患者
    selectPatient(row) {
      //console.log(typeof(row));
      //object
      //console.log(row);
      //console.log(row.patientId);
      sessionStorage.setItem("patient",JSON.stringify(row));
      this.patient = row;
    },
    //根据输入的内容搜索患者
    onSearch() {
      //console.log('search member:');
      //console.log(this.formInline.content);
      axios
        .get("api/menZhen/searchPatient", {
          params: {
            content: this.formInline.content
          }
        })
        .then(res => {
          //console.log(res);
          this.searchMember = res.data;
        })
        .catch(error => {
          console.log(error);
        })
    },

    zhenbi() {
      axios
        .get("api/menZhen/zhenbi", {
          params: {
            patientId: this.patient.patientId
          }
        })
        .then(res => {
          if(res.data > 0)
            this.$message({
              message: '诊断成功',
              type: 'success',
            });
        })
        .catch(error => {
          console.log(error);
        })
    },

  //---------------------------------病历首页-----------------------------
    //暂存按钮
    saveBingli() {
      sessionStorage.setItem("bingli", JSON.stringify(this.bingLiForm));
      sessionStorage.setItem("xiData", JSON.stringify(this.xiData));
      sessionStorage.setItem("zhongData", JSON.stringify(this.zhongData));
    },
    
    //提交按钮
    submitBingli() {
      if(this.patient.patientId == ''){
        this.$message({
          message: '请首先选中患者',
          type: 'warning',
        });
      }else{
        //console.log(JSON.stringify(this.bingLiForm));
        axios
          .post("api/menZhen/updatePatientInfo", {
          patientInfo: JSON.stringify(this.bingLiForm),
          solveXi: JSON.stringify(this.xiData),
          solveZhong: JSON.stringify(this.zhongData),
          patientId: this.patient.patientId
          })
          .then(res => {
            //console.log(res.data);
            if(res.data == 2)
              this.$message({
                message: '提交成功'
              })
            else{
              this.$message({
                message: '提交失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
      }
    },

    //刷新按钮
    refreshBingli() {
      //如果缓存里为空
      if(sessionStorage.getItem("bingli"))
        this.bingLiForm = JSON.parse(sessionStorage.getItem("bingli"));
      if(sessionStorage.getItem("xiData"))
        this.xiData = JSON.parse(sessionStorage.getItem("xiData"));
      if(sessionStorage.getItem("zhongData"))
        this.zhongData = JSON.parse(sessionStorage.getItem("zhongData"));
      
    },

    //清空按钮
    clearBingli() {
      //console.log(this.bingLiForm);
      this.bingLiForm.zhusu = '';
      this.bingLiForm.xianbing = '';
      this.bingLiForm.zhiliao = '';
      this.bingLiForm.jiwang = '';
      this.bingLiForm.guomin = '';
      this.bingLiForm.tige = '';
      this.bingLiForm.jianyi = '';
      this.bingLiForm.zhuyi = '';
      this.zhongData = [];
      this.xiData = [];
      sessionStorage.removeItem("xiData");
      sessionStorage.removeItem("zhongData");
      sessionStorage.removeItem("bingli");
    },

    //增加西医诊断
    updateXiData() {
      this.xiData.push({
        icd: '',
        name: '',
        time: ''
      })
    },

    //西医诊断复选框选中
    handleXiSelectionChange(val) {
      this.xiMulSelection = [];
      for(let item of val){
        this.xiMulSelection.push(item.index);
      }
      //console.log(this.xiMulSelection);
    },

    //删除西医诊断
    deleteXiData() {
      //console.log(this.xiMulSelection);
      let tmpSelection = this.xiMulSelection;
      let tmpTableData = this.xiData;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.xiData = tmpTableData;
      //console.log(this.xiData);
    },

    //中医诊断复选框选中
    handleZhongSelectionChange(val) {
      //console.log(val);
      this.zhongMulSelection = [];
      for(let item of val){
        this.zhongMulSelection.push(item.index);
      }
    },

    //增加中医诊断
    updateZhongData() {
      this.zhongData.push({
        icd: '',
        name: '',
        time: ''
      })
    },

    //删除中医诊断
    deleteZhongData() {
      //console.log(this.xiMulSelection);
      let tmpSelection = this.zhongMulSelection;
      let tmpTableData = this.zhongData;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.zhongData = tmpTableData;
      //console.log(this.xiData);
    },

  //---------------------------------申请公用---------------------------

    //得到申请模板的列表
    getApplyTemList() {
      axios
        .get("api/menZhen/getApplyTemList", {
          params: {
            type: '检查'
          }
        })
        .then(res => {
          //console.log(res);
          for(let item of res.data){
            this.temJianchaTable.push({
              name: item.temName,
              detail: item
            });
          }
        })
        .catch(error => {
          console.log(error);
        })
        axios
        .get("api/menZhen/getApplyTemList", {
          params: {
            type: '检验'
          }
        })
        .then(res => {
          //console.log(res);
          for(let item of res.data){
            this.temJianyanTable.push({
              name: item.temName,
              detail: item
            });
          }
        })
        .catch(error => {
          console.log(error);
        })
        axios
        .get("api/menZhen/getApplyTemList", {
          params: {
            type: '处置'
          }
        })
        .then(res => {
          //console.log(res);
          for(let item of res.data){
            this.temChuzhiTable.push({
              name: item.temName,
              detail: item
            });
          }
        })
        .catch(error => {
          console.log(error);
        })
    },

    //得到的检查结果 未完成
    getProResult(row) {
      console.log(row);
      if(row.state != '已开立'){
        this.$message({
          message: '项目未开立',
          type: 'warning',
        });
      }else if(this.patient.patientId == ''){
        this.$message({
          message: '请首先选中患者',
          type: 'warning',
        });
      }else{
        axios
        .get("api/menZhen/getProResult", {
          params: {
            patientId: this.patient.patientId,
            projName: row.proName,
          }
        })
        .then(res => {
          //console.log(res);
          this.jianchaPro[row.index].result = res.data;
          console.log(this.jianchaPro);
        })
        .catch(error => {
          console.log(error);
        })
      }
    },

  //---------------------------------检查申请---------------------------
    //处理检查申请复选框选中
    handleJianchaSelectionChange(val) {
      //console.log(val);
      this.jianchaMulSelection = [];
      this.jianchaNameList = [];
      this.jianchaStateList = [];
      for(let item of val){
        this.jianchaMulSelection.push(item.index);
        this.jianchaNameList.push(item.proName);
        this.jianchaStateList.push(item.state);
      }
    },

    //删去检查项目
    deleteJiancha() {
      //console.log(this.xiMulSelection);
      let tmpSelection = this.jianchaMulSelection;
      let tmpTableData = this.jianchaPro;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.jianchaPro = tmpTableData;
      this.jianchaCost = 0;
      for(let item of this.jianchaPro){
        this.jianchaCost += item.price;
      }
      //console.log(this.xiData);
    },

    //得到所有检查项目
    getJianchaAdd () {
      axios
        .get("api/menZhen/getPro", {
          params: {
            projType: '检查'
          }
        })
        .then(res => {
          //console.log(res);
          this.jianchaAdd = res.data;
        })
        .catch(error => {
          console.log(error);
        })
    },

    //处理增加检查项目增加复选框选中
    handleJianchaAddSelection(val) {
      this.jianchaAddSelection = val;
      //console.log(this.jianchaAddSelection);
    },

    //增加检查项目
    addJiancha() {
      for(let item of this.jianchaAddSelection){
        this.jianchaPro.push({
          applyName: '请填写',
          proName: item.projName,
          dept: item.deptId,
          state: '新建',
          price: item.price,
          result: ''
        })
      }
      this.jianchaCost = 0;
      for(let item of this.jianchaPro){
        this.jianchaCost += item.price;
      }
      this.$refs.jianchaAdd.clearSelection();
      //console.log(this.jianchaCost);
    },

    //暂存检查项目
    saveJianchaPro() {
      for(let item of this.jianchaPro){
        item.state = '暂存';
      }
      sessionStorage.setItem("jiancha", JSON.stringify(this.jianchaPro));
    },

    //刷新检查项目
    refreshJianchaPro() {
      if(sessionStorage.getItem("jiancha"))
        this.jianchaPro = JSON.parse(sessionStorage.getItem("jiancha"));
    },
    
    //提交检查项目
    submitJianchaPro() {
      if(this.patient.patientId == ''){
        this.$message({
          message: '请首先选中患者',
          type: 'warning',
        });
      }else{
        axios
          .post("api/menZhen/insertPro", {
              patientId: this.patient.patientId,
              projNameList: this.jianchaNameList
          })
          .then(res => {
            //console.log(res.data);
            if(res.data >= 1){
              this.$message({
                message: '开立成功'
              })
              //console.log(this.jianchaMulSelection);
              for(let i of this.jianchaMulSelection){
                this.jianchaPro[this.jianchaPro.findIndex(item => item.index === i)].state = '已开立';
              }
              this.$refs.jianchaPro.clearSelection();
            }else{
              this.$message({
                message: '开立失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
      }
    },

    //作废项目
    deleteJianchaPro(){
      console.log(this.jianchaStateList);
      var tag = true;
      for(let item of this.jianchaStateList){
        if(item != '已开立'){
          this.$message({
          message: '只有已开立的项目才可以作废',
          type: 'warning',
          });
          tag = false;
        }
      }
      if(tag){
        if(this.patient.patientId == ''){
          this.$message({
            message: '请首先选中患者',
            type: 'warning',
          });
        }else{
        axios
          .post("api/menZhen/deletePro", {
              patientId: this.patient.patientId,
              projNameList: this.jianchaNameList
          })
          .then(res => {
            //console.log(res.data);
            if(res.data >= 1){
              this.$message({
                message: '作废成功'
              })
              for(let i of this.jianchaMulSelection){
                this.jianchaPro[this.jianchaPro.findIndex(item => item.index === i)].state = '已作废';
              }
              this.$refs.jianchaPro.clearSelection();
            }else{
              this.$message({
                message: '作废失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
        }
      }
    },

    //使用检查模板
    useJianchaTem(row) {
      //console.log(row);
      axios
        .get("api/menZhen/getTemPro", {
          params: {
            temName: row.name,
            type: '检查'
          }
        })
        .then(res => {
          console.log(res.data);
          for(let item of res.data){
            this.jianchaPro.push({
              applyName: row.name,
              proName: item.projName,
              dept: item.deptId,
              state: '新建',
              price: item.price
            })
          }
        })
        .catch(error => {
          console.log(error);
        })
    },

  //---------------------------------检验申请---------------------------
    handleJianyanSelectionChange(val) {
      this.jianyanMulSelection = [];
      this.jianyanNameList = [];
      this.jianyanStateList = [];
      for(let item of val){
        this.jianyanMulSelection.push(item.index);
        this.jianyanNameList.push(item.proName);
        this.jianyanStateList.push(item.state);
      }
    },

    deleteJianyan() {
      let tmpSelection = this.jianyanMulSelection;
      let tmpTableData = this.jianyanPro;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.jianyanPro = tmpTableData;
      this.jianyanCost = 0;
      for(let item of this.jianyanPro){
        this.jianyanCost += item.price;
      }
    },

    getJianyanAdd () {
      axios
        .get("api/menZhen/getPro", {
          params: {
            projType: '检验'
          }
        })
        .then(res => {
          this.jianyanAdd = res.data;
        })
        .catch(error => {
          console.log(error);
        })
    },

    handleJianyanAddSelection(val) {
      this.jianyanAddSelection = val;
    },

    addJianyan() {
      for(let item of this.jianyanAddSelection){
        this.jianyanPro.push({
          applyName: '请填写',
          proName: item.projName,
          dept: item.deptId,
          state: '新建',
          price: item.price,
          result: ''
        })
      }
      this.jianyanCost = 0;
      for(let item of this.jianyanPro){
        this.jianyanCost += item.price;
      }
      this.$refs.jianyanAdd.clearSelection();
    },

    saveJianyanPro() {
      for(let item of this.jianyanPro){
        item.state = '暂存';
      }
      sessionStorage.setItem("jianyan", JSON.stringify(this.jianyanPro));
    },

    refreshJianyanPro() {
      if(sessionStorage.getItem("jianyan"))
        this.jianyanPro = JSON.parse(sessionStorage.getItem("jianyan"));
    },
    
    submitJianyanPro() {
      if(this.patient.patientId == ''){
        this.$message({
          message: '请首先选中患者',
          type: 'warning',
        });
      }else{
        axios
          .post("api/menZhen/insertPro", {
              patientId: this.patient.patientId,
              projNameList: this.jianyanNameList
          })
          .then(res => {
            if(res.data >= 1){
              this.$message({
                message: '开立成功'
              })
              for(let i of this.jianyanMulSelection){
                this.jianyanPro[this.jianyanPro.findIndex(item => item.index === i)].state = '已开立';
              }
              this.$refs.jianyanPro.clearSelection();
            }else{
              this.$message({
                message: '开立失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
      }
    },

    deleteJianyanPro(){
      console.log(this.jianyanStateList);
      var tag = true;
      for(let item of this.jianyanStateList){
        if(item != '已开立'){
          this.$message({
          message: '只有已开立的项目才可以作废',
          type: 'warning',
          });
          tag = false;
        }
      }
      if(tag){
        if(this.patient.patientId == ''){
          this.$message({
            message: '请首先选中患者',
            type: 'warning',
          });
        }else{
        axios
          .post("api/menZhen/deletePro", {
              patientId: this.patient.patientId,
              projNameList: this.jianyanNameList
          })
          .then(res => {
            if(res.data >= 1){
              this.$message({
                message: '作废成功'
              })
              for(let i of this.jianyanMulSelection){
                this.jianyanPro[this.jianyanPro.findIndex(item => item.index === i)].state = '已作废';
              }
              this.$refs.jianyanPro.clearSelection();
            }else{
              this.$message({
                message: '作废失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
        }
      }
    },

    useJianyanTem(row) {
      axios
        .get("api/menZhen/getTemPro", {
          params: {
            temName: row.name,
            type: '检验'
          }
        })
        .then(res => {
          console.log(res.data);
          for(let item of res.data){
            this.jianyanPro.push({
              applyName: row.name,
              proName: item.projName,
              dept: item.deptId,
              state: '新建',
              price: item.price
            })
          }
        })
        .catch(error => {
          console.log(error);
        })
    },

  //---------------------------------门诊确诊---------------------------
    //导入按钮，导入诊断和检查，检验信息
    importQuezhen() {
      if(this.patient.patientId == ''){
        this.$message({
          message: '请首先选中患者',
          type: 'warning',
        });
      }else{
        axios
          .get("api/menZhen/getXiData", {
            params: {
              patientId: this.patient.patientId
            }
          })
          .then(res => {
            //console.log(res.data);
            this.xiQuezhenData = res.data;
          })
          .catch(err => {
          console.log(err);
          })
        axios
          .get("api/menZhen/getZhongData", {
            params: {
              patientId: this.patient.patientId
            }
          })
          .then(res => {
            this.zhongQuezhenData = res.data;
          })
          .catch(err => {
          console.log(err);
          })
        axios
          .get("api/menZhen/getJianchaData", {
            params: {
              patientId: this.patient.patientId
            }
          })
          .then(res => {
            //console.log(res.data);
            var output = [];
            for(let item of res.data){
              output.push(item.project_name + ' : ' + item.result);
            }
            this.quezhenForm.jianchaResult = output.join('\n');
          })
          .catch(err => {
          console.log(err);
          })
        axios
          .get("api/menZhen/getJianyanData", {
            params: {
              patientId: this.patient.patientId
            }
          })
          .then(res => {
            var output = [];
            for(let item of res.data){
              output.push(item.project_name + ' : ' + item.result);
            }
            this.quezhenForm.jianyanResult = output.join('\n');
          })
          .catch(err => {
          console.log(err);
          })
      }
    },

    updateXiQuezhenData() {
      this.xiQuezhenData.push({
        icd: '',
        name: '',
        time: ''
      })
    },

    handleXiQuezhenSelectionChange(val) {
      this.xiQuezhenMulSelection = [];
      for(let item of val){
        this.xiQuezhenMulSelection.push(item.index);
      }
    },

    deleteXiQuezhenData() {
      let tmpSelection = this.xiQuezhenMulSelection;
      let tmpTableData = this.xiQuezhenData;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.xiQuezhenData = tmpTableData;
    },

    updateZhongQuezhenData() {
      this.zhongQuezhenData.push({
        icd: '',
        name: '',
        time: ''
      })
    },

    handleZhongQuezhenSelectionChange(val) {
      this.zhongQuezhenMulSelection = [];
      for(let item of val){
        this.zhongQuezhenMulSelection.push(item.index);
      }
    },

    deleteZhongQuezhenData() {
      let tmpSelection = this.zhongQuezhenMulSelection;
      let tmpTableData = this.zhongQuezhenData;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.zhongQuezhenData = tmpTableData;
    },

    handleXiQuezhenSelectionChange(val) {
      this.xiQuezhenMulSelection = [];
      for(let item of val){
        this.xiQuezhenMulSelection.push(item.index);
      }
    },

    handleZhongQuezhenSelectionChange(val) {
      this.zhongQuezhneMulSelection = [];
      for(let item of val){
        this.zhongQuezhenMulSelection.push(item.index);
      }
    },

    submitQuehzhen() {
      if(this.patient.patientId == ''){
        this.$message({
          message: '请首先选中患者',
          type: 'warning',
        });
      }else{
        //console.log(JSON.stringify(this.bingLiForm));
        axios
          .post("api/menZhen/updateQuezhen", {
          solveXi: JSON.stringify(this.xiQuezhenData),
          solveZhong: JSON.stringify(this.zhongQuezhenData),
          patientId: this.patient.patientId
          })
          .then(res => {
            //console.log(res.data);
            if(res.data == 1)
              this.$message({
                message: '提交成功'
              })
            else{
              this.$message({
                message: '提交失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
      }
    },

  //---------------------------------处置申请---------------------------
    handleChuzhiSelectionChange(val) {
      this.ChuzhiMulSelection = [];
      this.ChuzhiNameList = [];
      this.ChuzhiStateList = [];
      for(let item of val){
        this.chuzhiMulSelection.push(item.index);
        this.chuzhiNameList.push(item.proName);
        this.chuzhiStateList.push(item.state);
      }
    },

    deleteChuzhi() {
      let tmpSelection = this.chuzhiMulSelection;
      let tmpTableData = this.chuzhiPro;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.chuzhiPro = tmpTableData;
      this.chuzhiCost = 0;
      for(let item of this.chuzhiPro){
        this.chuzhiCost += item.price;
      }
    },

    getChuzhiAdd () {
      axios
        .get("api/menZhen/getPro", {
          params: {
            projType: '处置'
          }
        })
        .then(res => {
          this.chuzhiAdd = res.data;
        })
        .catch(error => {
          console.log(error);
        })
    },

    handleChuzhiAddSelection(val) {
      this.chuzhiAddSelection = val;
    },

    addChuzhi() {
      for(let item of this.chuzhiAddSelection){
        this.chuzhiPro.push({
          applyName: '请填写',
          proName: item.projName,
          dept: item.deptId,
          state: '新建',
          price: item.price,
          result: ''
        })
      }
      this.chuzhiCost = 0;
      for(let item of this.chuzhiPro){
        this.chuzhiCost += item.price;
      }
      this.$refs.chuzhiAdd.clearSelection();
    },

    saveChuzhiPro() {
      for(let item of this.chuzhiPro){
        item.state = '暂存';
      }
      sessionStorage.setItem("chuzhi", JSON.stringify(this.chuzhiPro));
    },

    refreshChuzhiPro() {
      if(sessionStorage.getItem("chuzhi"))
        this.chuzhiPro = JSON.parse(sessionStorage.getItem("chuzhi"));
    },
    
    submitChuzhiPro() {
      if(this.patient.patientId == ''){
        this.$message({
          message: '请首先选中患者',
          type: 'warning',
        });
      }else{
        axios
          .post("api/menZhen/insertPro", {
              patientId: this.patient.patientId,
              projNameList: this.chuzhiNameList
          })
          .then(res => {
            if(res.data >= 1){
              this.$message({
                message: '开立成功'
              })
              for(let i of this.chuzhiMulSelection){
                this.chuzhiPro[this.chuzhiPro.findIndex(item => item.index === i)].state = '已开立';
              }
              this.$refs.chuzhiPro.clearSelection();
            }else{
              this.$message({
                message: '开立失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
      }
    },

    deleteChuzhiPro(){
      console.log(this.chuzhiStateList);
      var tag = true;
      for(let item of this.chuzhiStateList){
        if(item != '已开立'){
          this.$message({
          message: '只有已开立的项目才可以作废',
          type: 'warning',
          });
          tag = false;
        }
      }
      if(tag){
        if(this.patient.patientId == ''){
          this.$message({
            message: '请首先选中患者',
            type: 'warning',
          });
        }else{
        axios
          .post("api/menZhen/deletePro", {
              patientId: this.patient.patientId,
              projNameList: this.chuzhiNameList
          })
          .then(res => {
            if(res.data >= 1){
              this.$message({
                message: '作废成功'
              })
              for(let i of this.chuzhiMulSelection){
                this.chuzhiPro[this.chuzhiPro.findIndex(item => item.index === i)].state = '已作废';
              }
              this.$refs.chuzhiPro.clearSelection();
            }else{
              this.$message({
                message: '作废失败',
                type: 'warning'
              })
            }
          })
          .catch(err => {
          console.log(err);
          })
        }
      }
    },

    useChuzhiTem(row) {
      axios
        .get("api/menZhen/getTemPro", {
          params: {
            temName: row.name,
            type: '处置'
          }
        })
        .then(res => {
          console.log(res.data);
          for(let item of res.data){
            this.chuzhiPro.push({
              applyName: row.name,
              proName: item.projName,
              dept: item.deptId,
              state: '新建',
              price: item.price
            })
          }
        })
        .catch(error => {
          console.log(error);
        })
    },
  //---------------------------------成药处方---------------------------
    //增加门诊处方表格的一行
    updateXiChufangData() {
      this.chufangXiData.push({
        name: '',
        state: '暂存'
      })
    },

    //门诊处方复选框选中
    handleXiChufangSelectionChange(val) {
      this.chufangXiMulSelection = [];
      for(let item of val){
        this.chufangXiMulSelection.push(item.index);
      }
    },

    //删除门诊处方选中项
    deleteXiChufangData() {
      let tmpSelection = this.chufangXiMulSelection;
      let tmpTableData = this.chufangXiData;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.ChufangXiData = tmpTableData;
      this.selectedXiChufangIndex = -1;
    },

    getXiDrugList() {
      axios
        .get("api/menZhen/selectDrugByType", {
          params: {
            type: 'xi'
          }
        })
        .then(res => {
          for(let item of res.data){
            this.drugXiTableData.push({
              name: item.drugName,
              standard: item.drugStandard,
              price: item.drugUnitprice,
              use: item.drugUse,
              dose: item.drugDose,
              fre:  item.drugFre,
            });
            this.drugXiCommon.push({
              name: item.drugName,
              standard: item.drugStandard,
              price: item.drugUnitprice,
              use: item.drugUse,
              dose: item.drugDose,
              fre:  item.drugFre
            });
          }
        })
        .catch(error => {
          console.log(error);
        })
    },

    handleDrugXiSelectionChange(val) {
      this.drugXiAdd = val;
    },

    addXiDrug() {
      for(let item of this.drugXiAdd){
        this.drugXiList.push({
          name: item.name,
          standard: item.standard,
          price: item.price,
          use: item.use,
          dose: item.dose,
          fre:  item.fre,
          num: 1
        });
      }
      this.$refs.drugXiTableData.clearSelection();
    },

    handleDrugXiListSelectionChange(val) {
      this.drugListXiMulSelection = [];
      for(let item of val){
        this.drugListXiMulSelection.push(item.index);
      }
    },

    deleteXiDrug() {
      let tmpSelection = this.drugListXiMulSelection;
      let tmpTableData = this.drugXiList;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.drugXiList = tmpTableData;
    },

    refreshXiCost() {
      var cost = 0;
      for(let item of this.drugXiList){
          cost += item.num * item.price;
      }
      return cost;
    },

    searchXiTem() {
      axios
        .get("api/menZhen/searchTemByName", {
          params: {
            content: this.formTemXiSearch.content,
            type: '西药'
          }
        })
        .then(res => {
          //console.log(res.data);
          this.searchXiTemplate = res.data;
        })
        .catch(error => {
          console.log(error);
        })
    },

    selectXiTem(row) {
      //console.log(row.tem_name);
      this.selectedXiTemName = row.tem_name;
      axios
        .get("api/menZhen/searchTemContent", {
          params: {
            temName: row.tem_name,
          }
        })
        .then(res => {
          //console.log(res.data);
          for(let item of res.data){
            this.mubanXiData.push({
              name: item.drugName,
              standard: item.drugStandard,
              price: item.drugUnitprice,
              use: item.drugUse,
              dose: item.drugDose,
              fre:  item.drugFre
            });
          }
        })
        .catch(error => {
          console.log(error);
        })
    },

    useXiMuban() {
      this.drugXiList = this.mubanXiData;
      for(let item of this.drugXiList){
        item.num = 1;
      }
      this.chufangXiData.push({
        name: this.selectedXiTemName,
        state: '暂存'
      });
    },

    handleXiClickChuFang(row) {
      //console.log(row);
      this.selectedXiChufangIndex = row.index;
    },

    saveXiChufang() {
      if(this.selectedXiChufangIndex == -1){
        this.$message({
          message: '请首先选中处方',
          type: 'warning'
        });
      }else{
        this.chufangXiData[this.selectedXiChufangIndex].drugList = this.drugXiList;
        this.chufangXiData[this.selectedXiChufangIndex].state = '已保存';
        //console.log(this.chufangData);
      }
    },

    boolXiIsSave() {
      var tag = false;
      for(let item of this.chufangXiData){
        if(item.state == '暂存')
          tag = true;
        //console.log(item.state);
      }
      return tag;
    },

    submitXiChufang() {
      if(this.patient.patientId == ''){
        this.$message({
              message: '请首先选中患者',
              type: 'warning'
        });
      }else if(this.boolXiIsSave()){
        this.$message({
            message: '请首先保存处方',
            type: 'warning'
        });
      }else{
        axios
        .post("api/menZhen/submitChufang", {
            chufang: this.chufangXiData,
            patientId: this.patient.patientId
        })
        .then(res => {
          //console.log(res.data);
          if(res.data > 0){
            this.$message({
              message: '提交成功',
              type: 'success'
            });
            for(let item of this.chufangXiData){
              item.state = '已开立';
            }
          }
        })
        .catch(error => {
          console.log(error);
        })
      }
    },

    deleteXiChufang() {
      if(this.patient.patientId == ''){
        this.$message({
              message: '请首先选中患者',
              type: 'warning'
        });
      }else if(this.boolXiIsSave()){
        this.$message({
            message: '请首先保存处方',
            type: 'warning'
        });
      }else{
        axios
        .post("api/menZhen/deleteChufang", {
            chufang: this.chufangXiData,
            patientId: this.patient.patientId
        })
        .then(res => {
          //console.log(res.data);
          if(res.data > 0){
            this.$message({
              message: '作废成功',
              type: 'success'
            });
          }
          for(let item of this.chufangXiData){
              item.state = '已作废';
          }
        })
        .catch(error => {
          console.log(error);
        })
      }
    },

  //---------------------------------草药处方---------------------------
    //增加门诊处方表格的一行
    updateZhongChufangData() {
      this.chufangZhongData.push({
        name: '',
        state: '暂存'
      })
    },

    //门诊处方复选框选中
    handleZhongChufangSelectionChange(val) {
      this.chufangZhongMulSelection = [];
      for(let item of val){
        this.chufangZhongMulSelection.push(item.index);
      }
    },

    //删除门诊处方选中项
    deleteZhongChufangData() {
      let tmpSelection = this.chufangZhongMulSelection;
      let tmpTableData = this.chufangZhongData;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.ChufangZhongData = tmpTableData;
      this.selectedZhongChufangIndex = -1;
    },

    getZhongDrugList() {
      axios
        .get("api/menZhen/selectDrugByType", {
          params: {
            type: 'zhong'
          }
        })
        .then(res => {
          for(let item of res.data){
            this.drugZhongTableData.push({
              name: item.drugName,
              standard: item.drugStandard,
              price: item.drugUnitprice,
              use: item.drugUse,
              dose: item.drugDose,
              fre:  item.drugFre,
            });
            this.drugZhongCommon.push({
              name: item.drugName,
              standard: item.drugStandard,
              price: item.drugUnitprice,
              use: item.drugUse,
              dose: item.drugDose,
              fre:  item.drugFre
            });
          }
        })
        .catch(error => {
          console.log(error);
        })
    },

    handleDrugZhongSelectionChange(val) {
      this.drugZhongAdd = val;
    },

    addZhongDrug() {
      for(let item of this.drugZhongAdd){
        this.drugZhongList.push({
          name: item.name,
          standard: item.standard,
          price: item.price,
          use: item.use,
          dose: item.dose,
          fre:  item.fre,
          num: 1
        });
      }
      this.$refs.drugZhongTableData.clearSelection();
    },

    handleDrugZhongListSelectionChange(val) {
      this.drugListZhongMulSelection = [];
      for(let item of val){
        this.drugListZhongMulSelection.push(item.index);
      }
    },

    deleteZhongDrug() {
      let tmpSelection = this.drugListZhongMulSelection;
      let tmpTableData = this.drugZhongList;
      for(let i of tmpSelection){
        tmpTableData.splice(tmpTableData.findIndex(item => item.index === i), 1);
      }
      this.drugZhongList = tmpTableData;
    },

    refreshZhongCost() {
      var cost = 0;
      for(let item of this.drugZhongList){
          cost += item.num * item.price;
      }
      return cost;
    },

    searchZhongTem() {
      axios
        .get("api/menZhen/searchTemByName", {
          params: {
            content: this.formTemZhongSearch.content,
            type: '中药'
          }
        })
        .then(res => {
          //console.log(res.data);
          this.searchZhongTemplate = res.data;
        })
        .catch(error => {
          console.log(error);
        })
    },

    selectZhongTem(row) {
      //console.log(row.tem_name);
      this.selectedZhongTemName = row.tem_name;
      axios
        .get("api/menZhen/searchTemContent", {
          params: {
            temName: row.tem_name,
          }
        })
        .then(res => {
          //console.log(res.data);
          for(let item of res.data){
            this.mubanZhongData.push({
              name: item.drugName,
              standard: item.drugStandard,
              price: item.drugUnitprice,
              use: item.drugUse,
              dose: item.drugDose,
              fre:  item.drugFre
            });
          }
        })
        .catch(error => {
          console.log(error);
        })
    },

    useZhongMuban() {
      this.drugZhongList = this.mubanZhongData;
      for(let item of this.drugZhongList){
        item.num = 1;
      }
      this.chufangZhongData.push({
        name: this.selectedZhongTemName,
        state: '暂存'
      });
    },

    handleZhongClickChuFang(row) {
      //console.log(row);
      this.selectedZhongChufangIndex = row.index;
    },

    saveZhongChufang() {
      if(this.selectedZhongChufangIndex == -1){
        this.$message({
          message: '请首先选中处方',
          type: 'warning'
        });
      }else{
        this.chufangZhongData[this.selectedZhongChufangIndex].drugList = this.drugZhongList;
        this.chufangZhongData[this.selectedZhongChufangIndex].state = '已保存';
        //console.log(this.chufangData);
      }
    },

    boolZhongIsSave() {
      var tag = false;
      for(let item of this.chufangZhongData){
        if(item.state == '暂存')
          tag = true;
        //console.log(item.state);
      }
      return tag;
    },

    submitZhongChufang() {
      if(this.patient.patientId == ''){
        this.$message({
              message: '请首先选中患者',
              type: 'warning'
        });
      }else if(this.boolZhongIsSave()){
        this.$message({
            message: '请首先保存处方',
            type: 'warning'
        });
      }else{
        axios
        .post("api/menZhen/submitChufang", {
            chufang: this.chufangZhongData,
            patientId: this.patient.patientId
        })
        .then(res => {
          //console.log(res.data);
          if(res.data > 0){
            this.$message({
              message: '提交成功',
              type: 'success'
            });
          }
          for(let item of this.chufangZhongData){
              item.state = '已开立';
          }
        })
        .catch(error => {
          console.log(error);
        })
      }
    },

    deleteZhongChufang() {
      if(this.patient.patientId == ''){
        this.$message({
              message: '请首先选中患者',
              type: 'warning'
        });
      }else if(this.boolZhongIsSave()){
        this.$message({
            message: '请首先保存处方',
            type: 'warning'
        });
      }else{
        axios
        .post("api/menZhen/deleteChufang", {
            chufang: this.chufangZhongData,
            patientId: this.patient.patientId
        })
        .then(res => {
          //console.log(res.data);
          if(res.data > 0){
            this.$message({
              message: '作废成功',
              type: 'success'
            });
          }
          for(let item of this.chufangZhongData){
            item.state = '已作废';
          }
        })
        .catch(error => {
          console.log(error);
        })
      }
    },
    
  //---------------------------------病历查询---------------------------
    handleTime(time) {
      return time.slice(0,10) + ' ' +  time.slice(11,19);
    },

    selectProCost(){
       axios
        .get("api/menZhen/selectProCost", {
          params: {
            patientId: this.costSearchInline.id,
            type: this.costSearchInline.type
          }
        })
        .then(res => {
          //console.log(res);
          this.costTable = res.data;
          for(let item of this.costTable){
            //console.log(typeof(item.time));  //string
            item.time = this.handleTime(item.time);
            item.cost = item.price * item.number;

          }
        })
        .catch(error => {
          console.log(error);
        })
    }
  }
}
</script>

<style>
  .el-tag {
    float: left;
  }

  .el-table {
    width: 100%;
  }

  .el-main {
    width: 100%;
    padding: 0px;
  }

  .main-row {
    width: 100%;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear:both;
  }

  .back {
    background-color:#7683852b;
  }
  
  p {
    height: 32px;
    text-align: left;
    margin-block-start: 8px;
  }


  .tb-edit .el-input{
    display: none;
  }

  .tb-edit .current-row .el-input {
    display: block;
  }

  .tb-edit .current-row .el-input+span {
    display: none;
  }

  .el-popover {
    padding: 0px;
  }
</style>